package org.flower.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.flower.dao.UserDao;
import org.flower.dao.impl.UserDaoImpl;
import org.flower.entity.CommodityDetails;
import org.flower.entity.User;
@WebServlet(urlPatterns="/user/UserInfo.shtml")
public class UserInfo extends HttpServlet {


	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			User user=(User)request.getSession().getAttribute("user") ;
			UserDao userDao = new UserDaoImpl();
			List<CommodityDetails> commList=userDao.getTop();
			User us = userDao.getByid(user.getId());
			request.getSession().setAttribute("user",us);
			String zhi= us.getPhone();
			int length =zhi.length(); 
			//获取手机号把中间的四位变成*号
			zhi=zhi.substring(0,3)+"****"+zhi.substring(length-4);
			request.setAttribute("phone",zhi);
			request.setAttribute("commList",commList);
			request.getRequestDispatcher("../UserInfo.jsp").forward(request, response);
	}


	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
